<?php

//Manga upload search autocomplete
if(isset($_GET['manga_upload_search'])){
	
		$val=$_GET['q'];
		$db=new db;
		$db->connect();
		if($_SESSION['user']['level']==4){
				$sql="select id,name from anime  WHERE  (upload_user='".$_SESSION['user']['username']."' or user_add='".$_SESSION['user']['username']."' or upload_user_add like '%".$_SESSION['user']['username']."%')  and alias   like '%".khongdau($val)."%'";
				
		}else{
		$sql="select id,name from anime  WHERE alias like '%".khongdau($val)."%'";
		}
		$db->query($sql);
		
		if($db->num_rows()>0){	
			$dt=$db->fetchAll();	
			foreach($dt as $row){				
					$answer[] = array("id"=>$row['id'],"text"=>$row['name']);		
			}
		}else{ 
		$answer[] = array("id"=>"0","text"=>"Không Tìm Thấy Kết quả");
		}
		
		$db->close();
		
		echo json_encode($answer);
		exit();


}
//--End manga search auto complete